import { Window_Selectable } from "@/windows/Window_Selectable.js";
import { TextManager } from "@/managers/TextManager.js";

export class Window_ItemCategory extends Window_Selectable {
    constructor(width,height) {
        super(width,height,false);
        this.init(width,height);
    }

    init(width,height){
        this.list=[
            TextManager.item,
            TextManager.weapon,
            TextManager.armor,
            TextManager.keyItem
        ];
        this.okHandler=null;
        this.cancelHandler=null;
        this.changedHandler=null;

        super.init(width,height);
    }

    column(){return 4;}
    viewColumn(){return 4;}
    length(){return this.list.length;}
    itemWidth(){return this.contentsWidth()/this.column();}

    drawItem(index,x,y,width,height){
        let item=this.list[index];
        if(item){
            this.drawText(item??'',x,y,width,height,'center');
        }
    }

    setHandler(name,callback){
        if(name=='ok'){
            this.okHandler=callback;
        }else if(name=='cancel'){
            this.cancelHandler=callback;
        }else if(name=='changed'){
            this.changedHandler=callback;
        }
    }

    onResponse(index){
        if(this.list[index].callback){
            this.list[index].callback(index);
        }else{
            this.okHandler?.(this.list[index],index);
        }
    }

    onSelectChanged(index,oldIndex){
        this.changedHandler?.(this.list[index],this.list[oldIndex]);
    }

    onCancel(){
        this.cancelHandler?.();
    }
}